<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.List" %>
<%@ page import="net.zdsoft.keel.util.DateUtils" %>
<%@ page import="net.zdsoft.keel.util.StringUtils" %>
<%@ page import="net.zdsoft.keel.util.Validators" %>
<%@ page import="net.zdsoft.keel.util.ArrayUtils" %>
<%@ page import="net.zdsoft.wpchat.support.util.PageUtils" %>
<%@ page import="net.zdsoft.wpchat.support.action.auth.OperatorAction" %>
<%@ page import="net.zdsoft.wpchat.support.entity.Operator" %>
<%@ page import="net.zdsoft.wpchat.support.entity.AuthGroup" %>
<%@ page import="net.zdsoft.wpchat.support.enums.OperatorStateEnum" %> 
<%@ page import="net.zdsoft.wpchat.support.enums.AuthGroupTypeEnum" %>
<%@ page import="net.zdsoft.wpchat.support.dto.OperatorDto" %> 
<%
OperatorAction action = (OperatorAction) PageUtils.getAction();
List<AuthGroup> groupList = action.getGroupList();
String regionId = action.getRegionId();
String regionName = action.getRegionName();
OperatorDto operator = action.getOperator();

String actionName = "addOperator.htm";
boolean isAdd = Validators.isEmpty(operator.getId());
boolean hasError = action.hasErrors();
if (!isAdd){
  actionName = "modifyOperator.htm";
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN" xml:lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>博客客户服务平台</title>
<style type="text/css" media="all">@import url("../../css/style.css");</style>
<script language="JavaScript">
</script>
</head>
<body>
<div id="tableMain">
  <div id="message"><%= PageUtils.allErrors(action) %></div>
  <div id="message"><%= PageUtils.messages() %></div>
  <div id="message">下面是基本信息</div>
  <form name="agentInfoForm" action="<%=actionName%>" method="post">
    <input type="hidden" name="operatorId" value="<%=isAdd && !hasError? "": StringUtils.ignoreNull(operator.getId())%>" />
    <table id="dataTable" border="0" align="center" cellpadding="5" cellspacing="1">
      <tr>
        <td width="20%" class="titleTd">用户帐号：</td>
        <td width="80%">
          <input type="text" name="loginName" maxlength="10" size="10" value="<%=isAdd && !hasError? "": StringUtils.htmlFilterToEmpty(operator.getLoginName())%>" />
        </td>
      </tr>
      <tr>
        <td width="20%" class="titleTd">姓名：</td>
        <td width="80%">
          <input type="text" name="name" maxlength="10" size="10" value="<%=isAdd && !hasError? "": StringUtils.htmlFilterToEmpty(operator.getName())%>" />
        </td>
      </tr>
      <tr>
        <td width="20%" class="titleTd">用户类型：</td>
        <td width="80%">
        <input id="type" name="type" type="radio" value="1" <%=operator.getType()==1?"checked":""%>>管理员</input><input id="type" name="type" type="radio" value="0" <%=operator.getType()==0?"checked":""%>>普通用户</input>
        </td>
      </tr>
    </table>
    <div id="message">所属组</div>
    <table id="dataTable" border="0" align="center" cellpadding="5" cellspacing="1"><%
for (int i = 0, length = groupList.size(); i < length; i++) {
    AuthGroup group = (AuthGroup)groupList.get(i);
    boolean isSelected = ArrayUtils.contains(operator.getGroupIds(),group.getId());
    String selected = isSelected && (!isAdd || hasError)? " checked=\"checked\"": "";
    if (!AuthGroupTypeEnum.SPECIAL.equals(group.getType()) || isSelected) { %>
      <tr>
        <td width="20%" class="titleTd"><%
        if (AuthGroupTypeEnum.SPECIAL.equals(group.getType())) { %>
          <input name="authGroup" disabled="disabled" type="checkbox" checked="checked" />
          <input name="groupIds" type="hidden" value="<%=group.getId()%>" /><%
        }
        else { %>
          <input name="groupIds" type="checkbox" value="<%=group.getId()%>" <%=selected%> /><%
        } %>
        </td>
        <td width="80%"><%=StringUtils.htmlFilter(group.getName())%></td>
      </tr><%
    }
} %>
    </table>
    <div id="buttonRight">
      <input type="submit" name="Submit" class="colorButton" value=" 保存 "/>
      <input type="button" onclick="document.location='listOperator.htm'"  class="colorButton" value=" 返回 "/>
    </div>
  </form>
</div>
</body>
</html>
